<include file="Common/header" />
    <div class="container">
        <div class="row">
            <div class="col-md-2">
                <include file="Common/left_siber" />
            </div>
            <div class="col-md-10">
                <div class="page-header"><h3>كاتىگورىيە باشقۇرۇش</h3></div>
                        <div class="btn-group  role="group" aria-label="" style="padding-bottom:10px;" >
                        <a  class="btn btn-default" href="{:U('Category/index')}">كاتىگورىيەلەر</a>&nbsp;
                        <a  class="btn btn-default" href="{:U('Category/add')}">كاتىگورىيە قۇشۇش</a>

            </div>
                <div>
                    <table class="table table-bordered ">
                        <thead>
                            <tr class="active">
                                <td>id</td>
                                <td>تەرتىپ</td>
                                <td>كاتىگورىيە نامى</td>
                                <td>ھالەت</td>
                                <td>مەشغۇلات</td>
                            </tr>
                        </thead>
                        <tbody>
                        <foreach name="categorys" item="c">
                            <tr>
                                <td>{$c['id']}</td>
                                 <td><input type="text" value="{$c['sort']}" onchange="changeSort(this,{$c['id']})"></td>
                                <td><if condition="$c['pid'] neq 0"><?php  echo str_repeat('&nbsp',$c['level']*8); ?></if>|{$c['cname']}</td>
                                   <td>
                                       <if condition="$c['status']">
                                           <span class="label label-success">ئۇچۇق</span>
                                           <else/>
                                           <span class="label label-danger">تاقاق</span>
                                       </if>
                                   </td>
                                   <td>
                                  <a class="btn btn-primary" href="{:U('Category/edit',array('id'=>$c['id']))}" >تەھرىرىلەش</a>
                                       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                  <a class="btn btn-danger" href="javascript:delCategory({$c['id']})">ئۈچۈرۈش</a>
                                  </td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                </div>
        </div>
        </div>
    </div>
<script>
    function changeSort(obj,id) {
        //alert(id);
        var csort = $(obj).val();
        $.ajax({
            'url': "{:U('Category/changeSort')}",
            'type': 'post',
            'dataType': 'json',
            'data': {'id':id, 'sort': csort},
            success:function(phpReturnData)
            {
                if (phpReturnData.status)
                {
                    layer.msg(phpReturnData.message, {'icon': 6}, function () {
                        window.location = location;
                    })
                }
            }
        })
    }
    function  delCategory(id) {
        layer.confirm('راستىنلا ئۆچۈرەمسىز؟', {
            btn: ['ھەئە','ياق'] //按钮
        }, function() {
            $.ajax({
                'url': "{:U('Category/delete')}",
                'type': 'POST',
                'dataType': 'json',
                'data': {'id': id},
                success: function (phpReturnData) {
                    //layer.msg(phpReturnData.message);
                    if (phpReturnData.status==1) {
                        layer.msg(phpReturnData.message, {'icon': 6}, function () {
                            window.location = location;
                        })
                    } else {
                        layer.msg(phpReturnData.message, {'icon': 5});
                    }
                }
            })
        })
    }
</Script>
<include file="Common/footer" />